#pragma once
#include<iostream>
#include<string>
#include<ctime>
#include<pthread.h>

using namespace std;
typedef void (*callback_t)();//定义函数指针
static int num=1;

class Thread
{
public:
    static void*Routine(void*args)
    {
        Thread* td=static_cast<Thread*>(args);
        td->Entery();
        return nullptr;
    }
    Thread(callback_t cb)
    :cb_(cb),name_(""),isrunning_(0),start_timestamp_(0),tid_(0)
    {}
    void Run()
    {
        //Thread*td=new Thread();
        name_="Thread-"+to_string(num++);
        start_timestamp_=time(nullptr);
        isrunning_=true;
        pthread_create(&tid_,nullptr,Routine,this);
    }
    void Join()
    {
        isrunning_=false;
        pthread_join(tid_,nullptr);
    }
    string Name()
    {
        return name_;
    }
    uint64_t StartTimeStamp()
    {
        return start_timestamp_;
    }
    bool IsRunning()
    {
        return isrunning_;
    }
    void Entery()
    {
        cb_();
    }
    ~Thread()
    {}
private:
    pthread_t tid_;
    string name_;
    uint64_t start_timestamp_;
    bool isrunning_;
    callback_t cb_;
};